package pl.poznan.put.cs.to.tsp.localsearch;

public class Edge {
	private int firstVertex;
	private int hashCode;
	private int secondVertex;

	public Edge(int firstVertex, int secondVertex) {
		this.firstVertex = firstVertex;
		this.secondVertex = secondVertex;
		this.hashCode = firstVertex ^ secondVertex;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}

		final Edge other = (Edge) obj;
		if (this.firstVertex == other.firstVertex
				&& this.secondVertex == other.secondVertex) {
			return true;
		}
		if (this.firstVertex == other.secondVertex
				&& this.secondVertex == other.firstVertex) {
			return true;
		}

		return false;
	}

	public int getFirstVertex() {
		return firstVertex;
	}

	public int getSecondVertex() {
		return secondVertex;
	}

	@Override
	public int hashCode() {
		return this.hashCode;
	}

	@Override
	public String toString() {
		return "[" + this.firstVertex + "->" + this.secondVertex + "]";
	}
}
